#include "../headers/Mailbox.h"


Mailbox::Mailbox() : capacity(-1)
{
}

Mailbox::Mailbox(int capacity) : capacity(capacity)
{
}

Mailbox::~Mailbox()
{
}

bool Mailbox::submitMessage(Message* msg) {
	if(capacity>0 && inbox.size() >= capacity)
		return false;
	inbox.push(msg);
	return true;

}

bool Mailbox::hasNewMessage(){
	return !inbox.empty();
}

Message* Mailbox::popMessage(){
	Message* ans=inbox.front();
	inbox.pop();
	return ans;
}

void Mailbox::clearMailbox(){
	while(!inbox.empty())
		delete popMessage();
}